<?php

namespace app\api\controller;

use app\BaseController;
use app\common\service\sys\UserService;

class Login extends BaseController
{
  public function index()
  {
    if (request()->isPost()) {
      //接收数据
      $data = [
        'username' => input('username', ''),
        'password' => input('password', ''),
        'captcha'  => input('code', ''),
        'key'      => input('key', '')
      ];

      if (empty($data['username'])) {
        return _jerr(3007);
      }
      if (empty($data['password'])) {
        return _jerr(3008);
      }
      $appid = $this->request->header('Kg-Appid');
      // 登录验证并获取包含访问令牌的用户
      $result = (new UserService())->login($data,$appid);
      return json($result);
    }
    return _jerr(1000);
  }
}
